package com.xuqm.sdhbwfu.app.ui

import android.graphics.Color
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.xuqm.base.adapter.CommonAdapter
import com.xuqm.base.adapter.ViewHolder
import com.xuqm.base.common.TimeHelper
import com.xuqm.base.ui.BaseActivity
import com.xuqm.sdhbwfu.app.R
import com.xuqm.sdhbwfu.app.databinding.ActivityJobListBinding
import com.xuqm.sdhbwfu.app.model.SchedulingModel
import com.xuqm.sdhbwfu.app.viewmodel.SchedulingViewModel
import com.xuqm.sdhbwfu.core.common.TIME_FORMAT_DATE
import com.xuqm.sdhbwfu.core.common.TIME_FORMAT_DATE_ALL_3
import com.xuqm.sdhbwfu.core.extensions.addItemDecorationForVertical

class JobListActivity : BaseActivity<ActivityJobListBinding>() {

    override fun getLayoutId(): Int = R.layout.activity_job_list
    override fun fullscreen(): Boolean = true


    private val vm: SchedulingViewModel by viewModels()
    private val mData = mutableListOf<SchedulingModel>()


    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)

        binding.jobListRv.layoutManager = LinearLayoutManager(mContext)
        binding.jobListRv.addItemDecorationForVertical(10)
        binding.jobListRv.adapter = adapter

        binding.schedulingTime.text="当前日期：${TimeHelper.getTimeString(TIME_FORMAT_DATE)}"

    }

    override fun lateInitView() {
        super.lateInitView()
        binding.inspectionBackLyt.setOnClickListener { finish() }
    }

    override fun initData() {
        super.initData()
        vm.list.observe(this) {
            mData.addAll(it)
            adapter.notifyDataSetChanged()
        }

        vm.inspectionList()
    }

    private val adapter =
        object : CommonAdapter<SchedulingModel>(R.layout.item_scheduling_list, mData) {
            override fun convert(holder: ViewHolder, item: SchedulingModel, position: Int) {
                holder.setBackgroundColor(R.id.item_app, Color.parseColor("#DBE3E6"))
                holder.setText(R.id.item_job_no, item.teamGroupName)
                holder.setText(R.id.item_job_name, item.dutyName)
                holder.setText(R.id.item_job_obj, item.dutyPhone)
                holder.setText(R.id.item_job_type, item.dutyEmail)
            }

        }

}